#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
struct node
{
	string kd;
	int HH;
	char s;
	int MM;
	int use;
	int wt;
}V[220],N[220];
int main()
{
	string kd;
	int HH;
	char s;
	int MM;
	int use;
	int wt;
	int cntn = 0;
	int cntv = 0;
	while(cin>>kd>>HH>>s>>MM>>use>>wt)
	{
		if(kd[0]=='V')
		{
			V[cntv].kd = kd;
			V[cntv].HH = HH;
			V[cntv].s = s;
			V[cntv].MM = MM;
			V[cntv].use = use;
			V[cntv].wt = wt;
			cntv++;
		}
		else 
		{
			N[cntn].kd = kd;
			N[cntn].HH = HH;
			N[cntn].s = s;
			N[cntn].MM = MM;
			N[cntn].use = use;
			N[cntn].wt = wt;
			cntn++;
		}
	}
	int ln = 0,lv = 0;
	int ans = 0;
	int now;
	if(cntn&&cntv)
		now = min(N[ln].HH*60+N[ln].MM,V[lv].HH*60+V[lv].MM);
	else if(cntn&&!cntv)
		now = N[ln].HH*60+N[ln].MM;
	else if(!cntn&&cntv)
		now = V[lv].HH*60+V[lv].MM;
	while(ln<cntn||lv<cntv)
	{
	//	printf("now = %d\n",now);
		int tn,tv;
		if(ln!=cntn)
			 tn = N[ln].HH*60+N[ln].MM;
		else tn = 0x3f3f3f3f;
		if(lv!=cntv)
			 tv = V[lv].HH*60+V[lv].MM;
		else tv = 0x3f3f3f3f;
		if(tn<tv)
		{
			cout<<N[ln].kd<<" "<<min(now-tn,N[ln].wt)<<" ";
			if(now-tn<=N[ln].wt)
			{
				cout<<"YES"<<endl;
				now += N[ln].use;
			}
			else cout<<"NO"<<endl;
			ln++;
		}
		else 
		{
			cout<<V[lv].kd<<" "<<min(now-tv,V[lv].wt)<<" ";
			if(now-tv<=V[lv].wt)
			{
				cout<<"YES"<<endl;
				now += V[lv].use;
				ans += V[lv].use;
			}
			else cout<<"NO"<<endl;
			lv++;
		}
	}
} 
